#include "app_get_temp.h"

/*************************define***************************************/
#define AM_PIN GET_PIN(G,6)
am_data temp_hum_data;
/*************************rt_thread***************************************/
struct rt_thread get_temp_thread;
/*************************rt_stack****************************************/
ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t rt_get_temp_thread_stack[2048];
/*************************rt_sem****************************************/
struct rt_semaphore sem_temp_available;




void get_temp_thread_entry(void* parameter)
{
	struct dht_device AM;
	dht_init(&AM, DHT11, AM_PIN);

	while(1)
	{
		rt_sem_take(&sem_temp_available,RT_WAITING_FOREVER);
		if(dht_read(&AM)) 
		{
			temp_hum_data.temp = dht_get_temperature(&AM);
			temp_hum_data.humi = (rt_uint32_t)(dht_get_humidity(&AM)/10);		
		}
		rt_sem_release(&sem_temp_available);
		rt_thread_mdelay(2100);
	}
}

int app_init_get_temp(void)
{
	 rt_sem_init(&sem_temp_available, "temp_sem", 1, RT_IPC_FLAG_PRIO);		
		//静态线程 - 屏幕数据刷新
	rt_thread_init(&get_temp_thread,              
								 "get_temp",                        	 
								 get_temp_thread_entry,           	
								 RT_NULL,                     		  	
								 &rt_get_temp_thread_stack[0],       
								 sizeof(rt_get_temp_thread_stack),  
								 get_temp_pro,    								 
								 20);                         		  
	rt_thread_startup(&get_temp_thread);

	return RT_EOK;
}
INIT_APP_EXPORT(app_init_get_temp);



